package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.service.INewpersonhongbaoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Newpersonhongbao;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 新用户注册红包 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/newpersonhongbao")
public class NewpersonhongbaoController extends BaseController
{
    private String prefix = "system/newpersonhongbao";
	
	@Autowired
	private INewpersonhongbaoService newpersonhongbaoService;
	
	@RequiresPermissions("system:newpersonhongbao:view")
	@GetMapping()
	public String newpersonhongbao()
	{
	    return prefix + "/newpersonhongbao";
	}
	
	/**
	 * 查询新用户注册红包列表
	 */
	@RequiresPermissions("system:newpersonhongbao:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Newpersonhongbao newpersonhongbao)
	{
		startPage();
        List<Newpersonhongbao> list = newpersonhongbaoService.selectNewpersonhongbaoList(newpersonhongbao);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出新用户注册红包列表
	 */
	@RequiresPermissions("system:newpersonhongbao:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Newpersonhongbao newpersonhongbao)
    {
    	List<Newpersonhongbao> list = newpersonhongbaoService.selectNewpersonhongbaoList(newpersonhongbao);
        ExcelUtil<Newpersonhongbao> util = new ExcelUtil<Newpersonhongbao>(Newpersonhongbao.class);
        return util.exportExcel(list, "newpersonhongbao");
    }
	
	/**
	 * 新增新用户注册红包
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存新用户注册红包
	 */
	@RequiresPermissions("system:newpersonhongbao:add")
	@Log(title = "新用户注册红包", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Newpersonhongbao newpersonhongbao)
	{		
		return toAjax(newpersonhongbaoService.insertNewpersonhongbao(newpersonhongbao));
	}

	/**
	 * 修改新用户注册红包
	 */
	@GetMapping("/edit/{newpersonhongbaoId}")
	public String edit(@PathVariable("newpersonhongbaoId") Integer newpersonhongbaoId, ModelMap mmap)
	{
		Newpersonhongbao newpersonhongbao = newpersonhongbaoService.selectNewpersonhongbaoById(newpersonhongbaoId);
		mmap.put("newpersonhongbao", newpersonhongbao);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存新用户注册红包
	 */
	@RequiresPermissions("system:newpersonhongbao:edit")
	@Log(title = "新用户注册红包", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Newpersonhongbao newpersonhongbao)
	{		
		return toAjax(newpersonhongbaoService.updateNewpersonhongbao(newpersonhongbao));
	}
	
	/**
	 * 删除新用户注册红包
	 */
	@RequiresPermissions("system:newpersonhongbao:remove")
	@Log(title = "新用户注册红包", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(newpersonhongbaoService.deleteNewpersonhongbaoByIds(ids));
	}
	
}
